package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.SetmealDish;
import com.itheima.dao.SetmaelDishDao;
import com.itheima.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SetmealDishServiceImpl implements SetmealDishService {
    @Autowired
    private SetmaelDishDao setmaelDishDao;

    @Override
    public List<SetmealDish> findById(Long id) {
        //创建条件对象
        LambdaQueryWrapper<SetmealDish> qw  = new LambdaQueryWrapper<>();
        //添加条件对象，根据setmealId的条件
        qw.eq(SetmealDish::getSetmealId,id);
        //根据Setmeal的id进行查询返回查询到的对象

        return setmaelDishDao.selectList(qw);
    }

    @Override
    public int add(SetmealDish setmealDish) {
        return setmaelDishDao.insert(setmealDish);
    }

    /*删除套餐里的菜品*/
    @Override
    public int delete(Long id) {
        //创建条件对象
        LambdaQueryWrapper<SetmealDish> qw = new LambdaQueryWrapper<>();
        //添加要删除的条件
        qw.eq(SetmealDish::getSetmealId,id);
        //删除菜品，返回影响行数
        return setmaelDishDao.delete(qw);
    }
}
